<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css"/>
    <link href="../../admin/css/font/dtreefont.css" rel="stylesheet"/>
    <link href="../../admin/css/dtree.css" rel="stylesheet"/>
    <link href="../../admin/css/pearCommon.css" rel="stylesheet"/>
</head>
<body>
<form class="layui-form" action="javascript:void(0);">
    <div  class="mainBox">
        <div class="layui-row" style="margin: 15px;">
            <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
                <div class="layui-form-item">
                    <label  class="layui-form-label">部门</label>
                    <div class="layui-input-block">
                        <ul id="selectParent" class="dtree" th:attr="data-value=${sysPost.deptId}" data-id="0" ></ul>
                    </div>
                </div>
            </div>
            <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
                <div class="layui-form-item">
                    <label class="layui-form-label">岗位</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" th:value="${sysPost.name}" required  lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md12 layui-col-sm12 layui-col-xs12" id="codeItem">
                <div class="layui-form-item">
                    <label class="layui-form-label">标识</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="${sysPost.code}" name="code" id="code"  placeholder=" 例如: manager" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md12 layui-col-sm12 layui-col-xs12" id="urlItem">
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="${sysPost.sort}" id="sort" name="sort" value="0" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md12 layui-col-sm12 layui-col-xs12">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input value="1" type="checkbox" lay-text="启用|禁用" name="status" checked lay-skin="switch">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../../component/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['iconPicker','form','layer','jquery','operate','dtree'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var operate = layui.operate;
        var dtree = layui.dtree;
        var iconPicker = layui.iconPicker;

        dtree.renderSelect({
            elem: "#selectParent",
            url: "/system/dept/tree",
            method:'get',
            selectInputName: {nodeId: "deptId", context: "name"},
            skin: "layui",
            dataStyle: "layuiStyle",
            dataFormat: "list",
            response:{message:"msg",statusCode:0, treeId: "id", parentId: "pid", title: "name"},  //修改response中返回数据的定义
            selectInitVal: "1"
        });


        //监听提交
        form.on('submit(formDemo)', function(data){

            $.ajax({
                url:'/system/post/update',
                type:'put',
                dataType:'json',
                data:JSON.stringify(data.field),
                contentType: 'application/json; charset=UTF-8',
                success:function(result){
                    if(result.code==200){
                        layer.msg(result.msg,{icon:1,time:1000},function(){

                            //关闭当前窗体
                            parent.layui.table.reload('postTable');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);

                        });
                    }else{
                        layer.msg(result.msg,{icon:2,time:1000});
                    }
                }
            });

        });
    });
</script>
</body>
</html>